<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
<script type="text/javascript" src="<%=request.getContextPath()%>/resource/lib/plugins/ajaxfileupload.js"></script>
<script type="text/javascript">
	$(function() {
		initUploadGrid();//初始化结构化上传
	});
	
	var mateGrid = null;
	//结构化上传
	function initUploadGrid(){
		
		var ctrlKey='3';// 1上传删除 2操作验证 3查看
		<c:if test="${detailFlag!=true }">
			ctrlKey='1';
      	</c:if>
		
		
		mateGrid = $("#mateGrid1").ligerGrid({
            url: '<%=request.getContextPath()%>/rfbase/fribaseinfo/recordInfoFileList.do?friId=${param.friId}',
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h = rowdata.datNm;
                        if(rowdata.isMust == 1){
                            h += '(<span style="color:red;">*</span>)';
                        }
                        return h;
                    }
                },
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                //{display: '状态', name: 'audStsCdNm', width: 100, align: 'left', enabledSort: false},
                {display: '操作', name: 'upLoadNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(rowdata.fileId){
                            if((ctrlKey==1 || ctrlKey==4) && rowdata.cfgCd !='PRJ006' && rowdata.cfgCd !='PRJ007'){
                            	if(!(rowdata.cfgCd =='PRJ015' && rowdata.cfgDtlCd=='242')){
                            		h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1)"></span>';
                            	}
                            	//if(rowdata.audStsCd!=1) {
                                    h+='<span class="sq-button sq-button-round fileupload-button" onclick="delFile(' + rowdata.fileId + ',\''+rowdata.orgCd+'\',1);">删除</span>';
                                //}
                            	
                            }else if(ctrlKey==2){
                                if("FLOW_00000008_002_002_029" == taskDefKey || "FLOW_00000008_007_002_031" == taskDefKey){
                                }else{
                                    if(rowdata.filePath) {
                                        h += '<a class="sq-button-hasicon  button_tongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',1,1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                        h += '<a class="sq-button-hasicon  button_butongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',2,1);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                                    }
                                }

                            }
                        }else{
                            if((ctrlKey==1 || ctrlKey==4) && rowdata.cfgCd !='PRJ006'&& rowdata.cfgCd !='PRJ007'){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1)"></span>';
                            }
                        }
                        return h;
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,

            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: function (s) {
                $('#mateGrid1').rowspan('datNm');//合并单元格
                //显示验证的抵押结果
                /* if (typeof showCheckMgt != 'undefined' && showCheckMgt instanceof Function) {
                	showCheckMgt();
                } */
            }
        });
	}
	
	
	 //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
	
    function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd,typ) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath="rfbase/fribaseinfo";
        

        $.ajaxFileUpload({
            url: '<%=request.getContextPath()%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {
                                'fileParams': JSON.stringify(msg.data),
                                'friId': '${param.friId}',
                                'cfgCd': cfgCd,
                                'cfgDtlCd': cfgDtlCd
                            },
                            url: '<%=request.getContextPath()%>/rfbase/fribaseinfo/uploadRecordInfoFile.do',
                            success: function (msg) {
                                wait_dialog.close();
                                if (msg.success == 1) {
                                       mateGrid.reload();
                                } else {
                                    $.ligerDialog.SQalert({content: "资料上传失败", SQ_type: "error"});
                                }
                            }
                        });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    //删除文件
    function delFile(_fileId,_orgCd,typ){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'id':'','fileId':_fileId,'orgCd':_orgCd},
            url: '<%=request.getContextPath()%>/capital/capPayInfo/removeMate.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    mateGrid.reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    
    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=request.getContextPath()%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else if(SQ.regs.img.test(_url)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=request.getContextPath()%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }
    
    function downloadFileByUrl() {
        var data = mateGrid.getData();
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            if(data[i].fileId){
                ids.push(data[i].fileId);
            }
        }
        if(ids.length <= 0){
            $.ligerDialog.SQalert({content:"没有要下载的附件！", SQ_type: "error"});
            return;
        }
        var actoinURL = '<%=request.getContextPath()%>/system/sysulfilesrec/zipDownloadById.do';
        var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }
    
</script>
</head>
<body class="iframeBody">
 <div class="Wrapper">
<div class="fieldset1 tabel_col tabel_col_s clearFix">
		       					<div id="mtgDiv" style="color: red;"></div>
	                            <div class="caption">
	                                <span class="title">上传附件信息 </span>
	                            </div>
<div class="sqPanel">
	<div class="sqPanel_head inL">
		<span>资料</span>
		 <span class="sq-button sq-button-round" onclick="downloadFileByUrl();">打包下载</span>
	</div>
	<div class="sqPanel_body">
		<div id="mateGrid1" class="sq-grid"></div>
	</div>
</div>
</div>
</body>
</html>
